package top.techqi.usbd.desc

import top.techqi.core.kext.WORD_T

class LangidDesc(
    bLength: Byte,
    vararg val wLANGID: Short
) : AbstractDesc(bLength, TYPE) {
    constructor(bytes: ByteArray) : this(
        bytes[0],
        *ShortArray((bytes[0] - 2) / 2) { index ->
            WORD_T(bytes[3 + index * 2], bytes[2 + index * 2])
        }
    ) {
        require(bytes[1] == TYPE) {
            "Invalid type: ${bytes[1]}"
        }
    }

    companion object {
        const val TYPE: Byte = 0x03

        const val LANGID_EN_US: Short = 0x0409 // English (United States)
        const val LANGID_ZH_TW: Short = 0x0404 // Chinese (Traditional, Taiwan)
        const val LANGID_ZH_CN: Short = 0x0804 // Chinese (Simplified, PRC)
        const val LANGID_ZH_HK: Short = 0x0C04 // Chinese (Traditional, Hong Kong)
        const val LANGID_ZH_SG: Short = 0x1004 // Chinese (Simplified, Singapore)
    }
}
